package com.demo.webapp.ui.table.taglib;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.demo.webapp.ui.table.ColumnComponent;
import com.demo.webapp.ui.table.TableComponent;

/**
 * <p>
 *  Column标签使用在Table标签体内
 *  为Table标签提供Column的展示属性
 *  当Column执行后,Table标签将得到显示列的个数及属性等信息,在Table中进行渲染
 * <p>
 * 以下是一个配置例子:
 * <pre>
 * &lt;Menu name="indexMenuMore" title="More Examples"&gt;
 *   &lt;Item name="actionExample"  title="Example - 'action' attribute"
 *         <B>location="/menu/bullet"</B>/&gt;
 *   &lt;Item name="pageExample" title="Example - 'page' attribute"
 *         <B>page="/bulletmenu.jsp"</B>/&gt;
 * &lt;/Menu&gt;
 * </pre>
 * @author ryuu.kk
 * @version 1.0 $Date: 2012/04/28 at 15:40:39$ 
 */
public class ColumnTag extends TagSupport {

	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = 3906047799991146700L;
	
	//~ Instance fields ========================================================
    protected final static Log log = LogFactory.getLog(ColumnTag.class);
    // column名称
    private String name;
    // column数据属性
    private String property;
    // column数据格式化字符串
    private String format;
    // column数据隐藏
    private String hidden;
    // column标题
    private String title;
    // column可以排序
    private String sortable;
    // column的link
    private String url;
    // column的样式class
    private String columnClass;
    // table中head的class
    private String headerClass;
    // column中的值内容
    private String value;
    // column中包含的HTML代码
    private String innerHtml;
    // column中Head的HTML代码.如果为空,则使用column的一般性标题title或由模板决定
    private String headHtml;
    // column中Foot的HTML代码.如果为空,则使用column的一般性标题title或由模板决定
    private String footHtml;
    public int doStartTag() throws JspException {
    	
    	//取得显示对象
        TableComponent table = (TableComponent) pageContext.getAttribute(TableDisplayerTag.TABLE_COMPONENT_KEY);
        List<ColumnComponent> columnList = table.getColumnList();
        
        ColumnComponent column = new ColumnComponent();
       
        column.setName(name);
        column.setFormat(format);
        column.setColumnClass(columnClass);
        column.setHidden(hidden);
        column.setId(id);
        column.setInnerHtml(innerHtml);
        column.setTitle(title);
        column.setValue(value);
        column.setProperty(property);
        column.setHeaderClass(headerClass);
        column.setSort("true".equals(sortable) ? name : "");
        column.setSortable("true".equals(sortable));
        column.setUrl(url);
        column.setHeadHtml(headHtml);
        column.setFootHtml(footHtml);
        columnList.add(column);
        
        return SKIP_BODY;
    }
    public int doEndTag() throws JspException {

    	return EVAL_PAGE;
    }
    
    public void release() {
        this.name = null;
    }
    
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getProperty() {
		return property;
	}
	public void setProperty(String property) {
		this.property = property;
	}
	public String getFormat() {
		return format;
	}
	public void setFormat(String format) {
		this.format = format;
	}
	public String getHidden() {
		return hidden;
	}
	public void setHidden(String hidden) {
		this.hidden = hidden;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getSortable() {
		return sortable;
	}
	public void setSortable(String sortable) {
		this.sortable = sortable;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getColumnClass() {
		return columnClass;
	}
	public void setColumnClass(String clazz) {
		this.columnClass = clazz;
	}
	public String getHeaderClass() {
		return headerClass;
	}
	public void setHeaderClass(String headerClass) {
		this.headerClass = headerClass;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getInnerHtml() {
		return innerHtml;
	}
	public void setInnerHtml(String innerHtml) {
		this.innerHtml = innerHtml;
	}
	public String getHeadHtml() {
		return headHtml;
	}
	public void setHeadHtml(String headerHtml) {
		this.headHtml = headerHtml;
	}
	public String getFootHtml() {
		return footHtml;
	}
	public void setFootHtml(String footHtml) {
		this.footHtml = footHtml;
	}
}
